package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    TbClueTrackRecordMapper clueTrackRecordMapper;

    @Autowired
    TbClueMapper clueMapper;

    /**
     * 新增线索跟进记录
     * @param tbClueTrackRecord
     */
    @Override
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
        TbClueTrackRecord clueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord,clueTrackRecord);
        clueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        clueTrackRecordMapper.add(clueTrackRecord);

        TbClue clue = clueMapper.selectTbClueById(clueTrackRecord.getClueId());
        if (clue.getStatus().equals("1")){
            clue.setStatus("2");
            clueMapper.updateTbClue(clue);
        }
    }

    /**
     * 查询线索跟进记录列表
     * @param clueId
     * @return
     */
    @Override
    public TableDataInfo list(Long clueId) {

        List<TbClueTrackRecord> trackList = clueTrackRecordMapper.selectAllByClueId(clueId);

        TableDataInfo info = new TableDataInfo();
        info.setTotal(trackList.size());
        info.setRows(trackList);
        info.setCode(200);
        info.setMsg("成功");
        return info;
    }
}
